import request from './request'
import type { ApiResponse, TokenResponse } from '@/types/api'

export interface LoginPayload {
  tenantId: string
  username: string
  password: string
}

export interface RefreshPayload {
  refreshToken: string
}

export async function login(payload: LoginPayload): Promise<TokenResponse> {
  const response = await request.post<ApiResponse<TokenResponse>>('/auth/login', payload)
  return response.data.data
}

export async function refreshToken(payload: RefreshPayload): Promise<TokenResponse> {
  const response = await request.post<ApiResponse<TokenResponse>>('/auth/refresh', payload)
  return response.data.data
}
